home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / net.s5 / strecho.c < prev    next >
Text File  |  1989-12-17  |  473b  |  27 lines

  1. /*
  2.  * Read a stream socket one line at a time, and write each line back
  3.  * to the sender.
  4.  *
  5.  * Return when the connection is terminated.
  6.  */
  7.  
  8. #define    MAXLINE    512
  9.  
  10. str_echo(sockfd)
  11. int    sockfd;
  12. {
  13.     int    n;
  14.     char    line[MAXLINE];
  15.  
  16.     for ( ; ; ) {
  17.         n = readline(sockfd, line, MAXLINE);
  18.         if (n == 0)
  19.             return;        /* connection terminated */
  20.         else if (n < 0)
  21.             err_dump("str_echo: readline error");
  22.  
  23.         if (writen(sockfd, line, n) != n)
  24.             err_dump("str_echo: writen error");
  25.     }
  26. }
  27.